﻿@model CloudStorageLight.Core.Web.FilesVM
@{
    ViewBag.Title = "Cloud Storage Light " + Model.Current;
    Layout = "~/Views/Shared/_LayoutCloudStorage.cshtml";
    var clientDownloadPage = Model.CloudAccount.ClientDownloadPage;
    if (string.IsNullOrEmpty(clientDownloadPage))
    {
        clientDownloadPage = Url.Content("https://www.cloudstoragelight.com/explorer/publish.htm");
    }
    string path = Url.RouteUrl("files", new { id = "" }) + "/";
    string current = Model.Current.Length <= 3 ? "/" : Model.Current.Substring(1, Model.Current.Length - 2);
    string[] pathItems = current == "/" ? new string[] { } : current.Split('/');
    int displayPathListSize = this.Request.Browser.IsMobileDevice ? 1 : 2;
    bool disableLogin = CloudStorageLight.Core.SystemSettings.Instance.DisableLogin || (Model.CloudAccount.IsFtpAuthentication() && Model.CloudAccount.EMailAddress != Model.User.Name);
}

<header class="nrm nlm">

<div class="clearfix bg-darkBlue fg-white" id="header-cont">
    <div class="place-right">
        <div class="margin10">
            <i class="icon-user" style="font-size:medium;"></i>
            @(Model.User.Name.Split('@')[0])
            <a id="logoff" href="@Url.Action("LogOff", "Account")"><i class="icon-exit" title="logoff" style="background:white;color:blue;padding:10px;border-radius:50%"></i></a>
        </div>
    </div>
    <div class="place-left margin10">
        <nav class="horizontal-menu">
            <ul>
                @Html.Partial("_HomeCommand")
                @if (!this.Request.Browser.IsMobileDevice)
                {
                    <li><a id="download-command" class="command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdDownload)</a></li>
                    <li><a id="upload-command" class="command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdUpload)</a></li>
                }
                @if (!Model.User.IsGuest)
                {
                    @*<li><a id="mypage-command" class="command-link bg-hover-blue" href="@Url.Action("Index", "MyPage")">@(CloudStorageLight.Core.Web.ViewMessages.CmdMyPage)</a></li>*@
                    <li>
                        <a class="dropdown-toggle command-link" id="operation-command" href="#">@(CloudStorageLight.Core.Web.ViewMessages.CmdOperation)</a>
                        <ul class="dropdown-menu bg-darkBlue" data-role="dropdown">
                            @if (!this.Request.Browser.IsMobileDevice)
                            {
                                <li><a id="selectall-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdSelectAll)</a></li>
                                <li><a id="unselectall-command" class="command-link bg-hover-blue" href=" javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdUnSelectAll)</a></li>
                            }
                            else
                            {
                                <li><a id="upload-command" class="command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdUpload)</a></li>
                            }
                            <li class="divider"></li>
                            @if (!this.Request.Browser.IsMobileDevice)
                            {
                                <li><a id="move-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdMove)</a></li>
                            }
                            <li><a id="remove-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdRemove)</a></li>
                            @if (Model.BackupMode && Model.FolderControl)
                            {
                                <li><a id="compremove-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdDeleteCompletely)</a></li>
                                <li><a id="recover-command" class="command-link bg-hover-blue" href="javascript:void(0);" style="display:none;">@(CloudStorageLight.Core.Web.ViewMessages.CmdRecoverFiles)</a></li>
                            }
                            <li class="divider"></li>
                            <li><a id="newfolder-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdNewFolder)</a></li>
                            @if (Model.FolderControl)
                            {
                                <li><a id="removefolder-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdRemoveFolder)</a></li>
                                if (!this.Request.Browser.IsMobileDevice)
                                {
                                    <li><a id="folder-setup-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdFolderSetup)</a></li>

                                }

                                if (Model.BackupMode)
                                {
                                    <li><a id="list-deleted-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdListDeletedFiles)</a></li>
                                }
                            }
                            @if (Model.CloudAccount.CanUseTransferFile && !this.Request.Browser.IsMobileDevice)
                            {
                                <li class="divider"></li>
                                <li><a id="transfer-file-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdFileTransfer)</a></li>
                            }
                            @if (!disableLogin)
                            {
                                <li class="divider"></li>
                                <li><a id="changepassword-command" class="command-link bg-hover-blue" href="@Url.Action("Manage", "Account")">@(CloudStorageLight.Core.Web.ViewMessages.CmdChangePassword)</a></li>
                            }
                            @if (Model.HasImmediateCustomAuthInfo)
                            {
                                <li><a id="clear-customauth-command" class="command-link bg-hover-blue" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.MsgResetCustomAuthInfo)</a></li>
                            }

                            @if (Model.User.IsAdmin)
                            {
                                if (!disableLogin)
                                {
                                    <li><a id="showUserListCommand" class="command-link bg-hover-blue" href="@Url.Action("UserList", "Account")">@(CloudStorageLight.Core.Web.ViewMessages.CmdUserList)</a></li>
                                }
                                <li><a id="cloudSettingsCommand" class="command-link bg-hover-blue" href="@Url.Action("CloudSettings", "Settings")">@(CloudStorageLight.Core.Web.ViewMessages.CmdCloudAccountSettings)</a></li>
                                <li><a id="configurationCommand" class="command-link bg-hover-blue" href="@Url.Action("Configuration", "Settings")">@(CloudStorageLight.Core.Web.ViewMessages.MsgStorageConfiguration)</a></li>
                                <li><a id="viewLogCommand" class="command-link bg-hover-blue" href="@Url.Action("LogView", "Settings")">@(CloudStorageLight.Core.Web.ViewMessages.MsgLogView)</a></li>
                            }
                            <li class="divider"></li>
                            @if (!this.Request.Browser.IsMobileDevice && clientDownloadPage != "disable")
                            {
                                <li><a class="command-link bg-hover-blue" href="@clientDownloadPage" target="_blank">@(CloudStorageLight.Core.Web.ViewMessages.MsgDownloadExplore)</a></li>
                            }

                        </ul>
                    </li>
                }
            </ul>
        </nav>
    </div>
</div>





    @if (!Model.User.IsGuest)
    {
        if (Model.NotifyMessage != null)
        {
            <div class="notify-message">
                @(Model.NotifyMessage)
            </div>
        }
        <div class="clearfix">
            <div class="place-right">
                @if (Model.CloudAccount.CanFullTextSearch)
                {
                    <div class="input-control text @(this.Request.Browser.IsMobileDevice ? "size2" : "size4") margin10">
                        <input type="text" id="query" name="query" placeholder="Search..." value="">
                        <button id="search" class="btn-search"></button>
                    </div>
                }
            </div>
            <div class="place-left">
                <div class="input-control text margin10" style="height:auto;">
                    <nav class="breadcrumbs">
                        <ul>
                            @if (pathItems.Length <= displayPathListSize)
                            {
                                <li><a href="@Url.RouteUrl("files", new { id="" })/">Home</a></li>
                                int idx = 0;
                                foreach (var item in pathItems)
                                {
                                    path += Uri.EscapeDataString(item) + "/";
                                    <li>
                                        <a href="@(path)" class="processing-link">
                                            @(item)
                                            @if (Model.Folder != null && Model.Folder.IsPublic() && path.EndsWith(Model.Current))
                                            {
                                                <i class="icon-cloud"></i>
                                            }
                                        </a>
                                    </li>
                                    idx++;
                                }
                            }
                            else
                            {
                                <li>
                                    <a id="submenu" href="javascript:void(0);">...</a>
                                </li>
                                int idx = 0;
                                foreach (var item in pathItems)
                                {
                                    path += Uri.EscapeDataString(item) + "/";
                                    if (idx >= pathItems.Length - displayPathListSize)
                                    {
                                        <li>
                                            <a href="@(path)" class="processing-link">
                                                @(item)
                                                @if (Model.Folder != null && Model.Folder.IsPublic() && path.EndsWith(Model.Current))
                                                {
                                                    <i class="icon-cloud"></i>
                                                }
                                            </a>
                                        </li>
                                    }
                                    idx++;
                                }

                            }
                        </ul>
                    </nav>
                    @if (pathItems.Length > displayPathListSize)
                    {
                        int idx = 0;
                        path = Url.RouteUrl("files", new { id = "" }) + "/";

                        <ul id="subNavigationMenu" class="dropdown-menu bg-white" data-role="dropdown" style="position:absolute;">
                            <li><a href="@Url.RouteUrl("files", new { id="" })/">Home</a></li>
                            @foreach (var item in pathItems)
                            {
                                path += Uri.EscapeDataString(item) + "/";
                                if (idx < pathItems.Length - displayPathListSize)
                                {
                                <li>
                                    <a href="@(path)" class="processing-link">
                                        @(item)
                                    </a>
                                </li>
                                }
                                idx++;
                            }                        
                        </ul>
                    }

                </div>
            </div>
        </div>
    }
</header>

<div id="create-folder-dialog" style="display:none;">
    <input type="text" id="newFolderName" />
    <div>
        <button id="create-newFolder" class="button" type="button">OK</button>
        <button class="button" type="button" onclick="$('#create-folder-dialog').dialog('close');">Cancel</button>
    </div>
    @Html.Hidden("currentPath", Model.Current)
</div>

<div id="rename-dialog" style="display:none;">
    <input type="hidden" id="renameSrcPath" />
    <table style="width:100%;">
        <tr>
            <td>
                @Html.Hidden("renameDistDirectory", Model.Current)
                <input type="text" id="renameDistName" style="width:100%;" />
            </td>
        </tr>
    </table>
    <div>
        <button id="rename-command" class="button" type="button">OK</button>
        <button class="button" type="button" onclick="$('#rename-dialog').dialog('close');">Cancel</button>
    </div>
    @Html.Hidden("currentPath", Model.Current)
    @Html.Hidden("currentUser", Model.User.Name)
</div>

<div id="move-dialog" style="display:none;">
    <table style="width:100%;">
        <tr>
            <td>
                <div id="move-directory-list">
                </div>
            </td>
        </tr>
    </table>
    <div>
        <button id="move-exec-command" class="button" type="button">OK</button>
        <button class="button" type="button" onclick="$('#move-dialog').dialog('close');">Cancel</button>
    </div>
    @Html.Hidden("currentPath", Model.Current)
</div>

<div id="download-confirm-dialog" style="display:none;">
    <p>@(CloudStorageLight.Core.Web.ViewMessages.MsgConfirmDownloadZip)</p>
    <div>
        <button id="download-zip-command" class="button" type="button">YES</button>
        <button id="download-files-command" class="button" type="button">NO</button>
    </div>
</div>


<form method="post" id="upload" enctype="multipart/form-data">
    @if (!this.Request.Browser.IsMobileDevice)
    {
    <input type="file" id="upl" name="upl" style="display:none;" multiple />
    }
    else
    {
    <input type="file" id="upl" name="upl" style="display:none;" />
    }
    @Html.Hidden("current", (Model.Current))
    @Html.Hidden("uploadId", Guid.NewGuid().ToString("d"))
</form>

<div id="folder-cont" class="listview-outlook">
    <div id="contextMenu-dialog" style="display:none;" class="bg-white">
        <ul class="horizontal-menu compact" style="position: relative;z-index:1">
            @if (!Model.User.IsGuest)
            {
                <li><a id="download-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdDownload)</a></li>
                if (!this.Request.Browser.IsMobileDevice)
                {
                    <li><a id="showurl-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdShowUrlLink)</a></li>
                }   
                <li><a id="checkout-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdCheckOut)</a></li>
                <li><a id="checkin-context-command" class="context-command-link" href=" javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdCheckIn)</a></li>
                <li><a id="rename-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdRename)</a></li>
                <li><a id="remove-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdRemove)</a></li>
                if (Model.BackupMode)
                {
                    if (Model.FolderControl)
                    {
                        <li><a id="compremove-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdDeleteCompletely)</a></li>
                    }
                    <li><a id="history-context-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdVersion)</a></li>
                }
                if (Model.FolderControl)
                {
                    <li><a id="accesslog-command" class="context-command-link" href="javascript:void(0);">@(CloudStorageLight.Core.Web.ViewMessages.CmdAccessLog)</a></li>
                }
            }
        </ul>
    </div>

    <div class="search-result-message">
    </div>
    <div id="file-items">

    </div>
</div>


<div id="directorySettings" style="height:100%;width:100%;display:none;">
</div>

<div id="fileTransfer" style="height:100%;width:100%;display:none;">
</div>

<div id="file-drop-cont" style="display:none;">
    <span>
        @(CloudStorageLight.Core.Web.ViewMessages.MsgPleaseDropHere)
    </span>
</div>


<p id="page-top" style="display:none;"><a href="javascript:void(0);"><i class="icon-arrow-up-5"></i></a></p>

@section scripts{

    <script id="fileitem-template" type="text/x-jquery-tmpl">
        <div class="list">

            {{if Type == "Directory"}}
            <a href="${$data.Url()}" class="processing-link">
                <div class="list-content">
                    <i class="${$data.Icon()} icon"></i>
                    <div class="data">
                        <span class="list-title item-name">${Title}</span>
                    </div>
                </div>
            </a>
            {{else}}
            <div class="list-content">
                {{if $data.CanDirectDownload()}}
                  <a href="${$data.Url()}">
                {{else}}
                  <a href="${$data.AttachmentUrl()}">
                {{/if}}
                    {{if FullTextEntryDate }}
                    <i class="${$data.Icon()} icon fg-black"></i>
                    {{else}}
                    <i class="${$data.Icon()} icon"></i>
                    {{/if}}
                   </a>
                        <div class="blobfile data" data-href="${$data.AttachmentUrl()}">
                        <span class="list-title">
                            <input type="checkbox" class="item-checkbox" name="${Path}" />
                            <span class="item-name">${Title}</span>
                        </span>
                        <div class="list-subtitle">
                            <span class="owner-userid">${Owner}</span>
                            <span>${$data.LastModifiedString()}</span>
                            <span>${$data.SizeString()  }</span>
                            <span class="item-marker">
                                {{if CheckoutUser }}
                                <i class="icon-pop-out fg-darkRed checkout-user">${CheckoutUser}</i>
                                {{/if}}
                            </span>
                        </div>
                        <div class="list-description">
                            <a href="javascript:void(0);" class="item-description">${SearchContent}</a>
                        </div>
                        <span class="list-remark fg-darkRed">
                        </span>
                    </div>
                <div class="list-context-menu"></div>
            </div>
            {{/if}}
        </div>
    </script>

    <script id="snapshot-template" type="text/x-jquery-tmpl">
        <div class="list">

            <div class="list-content">
                <a href="${$data.Url()}">
                    <i class="icon-history icon"></i>
                    <div class="item-name">${$data.Name()}</div>
                    <div>${$data.snapshotString()}</div>
                </a>
            </div>
        </div>
    </script>

    <script id="deleted-template" type="text/x-jquery-tmpl">
        <div class="list">
            <div class="list-content">
                <i class="${$data.Icon()} icon"></i>
                <div class="blobfile data">
                    <span class="list-title">
                        <input type="checkbox" class="item-checkbox" name="${path}" />
                        <span class="item-name">${$data.Name()}</span>
                    </span>
                </div>
                <span class="list-remark fg-darkRed">
                </span>
            </div>
        </div>
    </script>

    <script id="accesslog-template" type="text/x-jquery-tmpl">
        <tr>
            <td>
                ${$data.AccessDateString()}
            </td>
            <td>
                ${$data.Name()}
            </td>
            <td>
                ${ActionName}
            </td>
            <td>
                ${UserName}
            </td>
        </tr>
    </script>

    <script id="fileitem-more-template" type="text/x-jquery-tmpl">
        <div class="morePage list">
            <i class="icon-download-2">@(CloudStorageLight.Core.Web.ViewMessages.MsgMoreData)</i>
        </div>
    </script>

    <script id="accesstoken-template" type="text/x-jquery-tmpl">
        <tr class="token-line">
            <td>
                <input type="checkbox" class="accessToken-inuse" />
            </td>
            <td>
                {{if name }}
                <span>${name}</span>
                <input class="accessToken-name" type="hidden" value="${name}" />
                {{else}}
                <input class="accessToken-name" type="text" />
                {{/if}}
            </td>
            <td>
                <input type="checkbox" class="accessToken-can-read" />
            </td>
            <td>
                <input type="checkbox" class="accessToken-can-write" />
            </td>
            <td>
                <input type="checkbox" class="accessToken-can-modify" />
            </td>
            <td>
                <input type="checkbox" class="accessToken-can-control" />
            </td>
        </tr>

    </script>

    <script type="text/javascript">
        @Html.Partial("_Message")

        $(function () {
            
            CloudStorageLight.StorageController.getFiles($("#file-items"), '@(HttpUtility.JavaScriptStringEncode(Model.Current))');

            var dragHelp = false;
            var dragCounter = 0;

            $(document).bind("dragenter", function (evt) {
                var oev = evt.originalEvent;
                if (!oev.dataTransfer.types || oev.dataTransfer.types.length == 0 || oev.dataTransfer.types[0] != "Files") return;
                evt.stopPropagation();
                evt.preventDefault();
                if (dragHelp) return;
                dragHelp = true;
                dragCounter++;
                $('#file-drop-cont').show();
            });

            $("#file-drop-cont").bind("dragleave", function (evt) {
                evt.stopPropagation();
                evt.preventDefault();
                if (!dragHelp) return;
                dragCounter--;
                if (dragCounter === 0) {
                    dragHelp = false;
                    $('#file-drop-cont').hide();
                }
            });

            $("#file-drop-cont").bind("drop", function () {
                dragHelp = false;
                $('#file-drop-cont').hide();
            });

            $("#file-drop-cont").click(function () {
                dragHelp = false;
                $('#file-drop-cont').hide();
            });

            $('#upload').fileupload({
                dropZone: $('#file-drop-cont'),
                singleFileUploads: true,
                maxChunkSize: 50000000,
                add: function (e, data) {
                    CloudStorageLight.StorageController.upload(data);
                    dragHelp = false;
                    $('#file-drop-cont').hide();
                },
                progressall: function (e, data) {
                    var progress = parseInt(data.loaded / data.total * 100, 10);
                    if (progress < 100)
                    {
                        $('#freezePanel .prog-percent').text(progress + '%');
                    } else {
                        $('#freezePanel .prog-percent').text('');
                    }
                },
                done: function (e, data) {
                }
            });

            var topBtn = $('#page-top');
            topBtn.hide();
            $(window).scroll(function () {
                if ($(this).scrollTop() > $(window).height()) {
                    topBtn.fadeIn();
                } else {
                    topBtn.fadeOut();
                }
            });
            topBtn.click(function () {
                $('body,html').animate({
                    scrollTop: 0
                }, 500);
                return false;
            });

            $(window).bottom({ proximity: 0.05 });

            $("#submenu").click(function (e) {
                e.stopPropagation();
                $("#subNavigationMenu").toggle();
            });

            $("body").on("click", "a.processing-link", function (event) {
                event.preventDefault();
                var dataUrl = $(this).attr("href");
                if (dataUrl != "") {
                    CloudStorageLight.StorageController.blockUI(null, false);
                    window.location.href = dataUrl;
                }

            });
        });

    </script>
}
